<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/plug/h-ui/css/H-ui.min.css" />
<style type="text/css">
.ml-80{
	margin-left: 80px;
}

.center{
	text-align: center;
}

label {
	font-size: 18px !important;
}
</style>
</head>
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-member-add">
		<input type="hidden" id="id" value="${shopCoupon.id}" name="id"/>
		<h3 class="center" style="color: blue;">停车券发放限制规则设置</h3>
		<h4 class="ml-80">
			<c:if test="${shopCoupon.limitModeType == 1}">
				<input id="timeRadio" type="radio" name="limitModeType" value="1" class="radioBtn" checked="checked">
			</c:if>
			<c:if test="${shopCoupon.limitModeType == 2}">
				<input id="timeRadio" type="radio" name="limitModeType" value="1" class="radioBtn">
			</c:if>
			<label for="timeRadio">时间段内发放限制模式:</label>
			<select name="couponLimitType" class="select ml-20" style="display: inline-block; width: 100px;">
				<c:if test="${shopCoupon.couponLimitType == 1}">
					<option value="1" selected="selected">每天</option>
				</c:if>
				<c:if test="${shopCoupon.couponLimitType != 1}">
					<option value="1">每天</option>
				</c:if>
				
				<c:if test="${shopCoupon.couponLimitType == 2}">
					<option value="2" selected="selected">每周</option>
				</c:if>
				<c:if test="${shopCoupon.couponLimitType != 2}">
					<option value="2">每周</option>
				</c:if>
				
				<c:if test="${shopCoupon.couponLimitType == 3}">
					<option value="3" selected="selected">每月</option>
				</c:if>
				<c:if test="${shopCoupon.couponLimitType != 3}">
					<option value="3">每月</option>
				</c:if>
				
				<c:if test="${shopCoupon.couponLimitType == 4}">
					<option value="4" selected="selected">每年</option>
				</c:if>
				<c:if test="${shopCoupon.couponLimitType != 4}">
					<option value="4">每年</option>
				</c:if>
			</select>
			<label>限制发放优惠卷张数</label>
			<input class="btn" type="button" value="+" onclick="toMoney(1);">
			<input type="number" style="width: 80px;height: 20px;" value="100" id="couponLimitNum" name="couponLimitNum">
			<input class="btn" type="button" value="-" onclick="toMoney(-1);">
			<lable>张</lable>
		</h4>	
		<h4 class="ml-80">
			<c:if test="${shopCoupon.limitModeType == 1}">
				<input id="inventoryRadio" type="radio" name="limitModeType" value="2" class="radioBtn">
			</c:if>
			<c:if test="${shopCoupon.limitModeType == 2}">
				<input id="inventoryRadio" type="radio" name="limitModeType" value="2" class="radioBtn" checked="checked">
			</c:if>
			<label for="inventoryRadio">总库存模式:</label>
			<lable class="ml-20">现有库存${shopCoupon.inventory == null ? 0 : shopCoupon.inventory}张，再添加</lable>
			<input type="number" style="width: 80px;height: 20px;"  id="inventoryIpt" name="inventory" >
			<lable>张</lable>
		</h4>	
			
		<div  class="mt-20 center">
			<input class="btn btn-primary radius del" type="button"  value="&nbsp;&nbsp;保存设置&nbsp;&nbsp;">
			<input class="btn btn-primary radius closes" type="button"  value="&nbsp;&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;&nbsp;">
		</div>
	</form>
</article>

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="${ctx}/static/plug/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/static/plug/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="${ctx}/static/plug/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="${ctx}/static/plug/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function() {
	$(".del").click(function() {
		var modeType = $('.radioBtn[name="modeType"]:checked ').val();
		var inventoryIpt = $('#inventoryIpt').val();
		var couponLimitNum = $('#couponLimitNum').val();
		if(modeType == 2) {
			if(!inventoryIpt) {
				layer.msg("库存值不能为空！");
				return;
			}
		}
		if(modeType == 1) {
			if(!couponLimitNum) {
				layer.msg("限制数量不能为空！");
				return;
			}
		}
		
		var data = $("#form-member-add").serialize();
		$.ajax({
			type : "POST",
			url : "${ctx}/shop/install",
			data:data,
			dataType : "json",
			success : function(result) {
				if(result.success){
					layer.msg(result.msg)
					var index = parent.layer.getFrameIndex(window.name);
					parent.reloadData(false);
					parent.layer.close(index);
				}else{
					layer.msg(result.meg);
					var index = parent.layer.getFrameIndex(window.name);
					parent.reloadData(false);
					parent.layer.close(index);
					
				}
			}
		});
	});
	
	$(".closes").click(function() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.reloadData(false);
		parent.layer.close(index);
	});
	
	
	
});
function toMoney(value) {
	if($("#couponLimitNum").val()<=0&value==-1){
		$("#couponLimitNum").val(0);
	}else{
		$("#couponLimitNum").val(parseInt($("#couponLimitNum").val())+parseInt(value)*10);
	}
}
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>